//
//  Dire_SendViewController.m
//  MagicBox
//
//  Created by dllo on 16/8/15.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "Dire_SendViewController.h"
#import <IJKMediaFramework/IJKMediaFramework.h>

@interface Dire_SendViewController ()
@property (nonatomic, retain) NSURL *url;
@property (nonatomic, retain) id<IJKMediaPlayback>player;
@property (nonatomic, retain) UIView *playerView;

@end

@implementation Dire_SendViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIImageView *imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"zhanweitu.png"]];
    imageview.frame = self.view.bounds;
    [self.view addSubview:imageview];
    
}

-(void)setModel:(Dire_Model *)model{
    _model = model;
    

    self.url = [NSURL URLWithString:_model.stream_addr];
    _player =[[IJKFFMoviePlayerController alloc]initWithContentURL:self.url withOptions:nil];
    UIView *playerView = [self.player view];
    UIView *displayView = [[UIView alloc]initWithFrame:self.view.bounds];
    self.playerView = displayView;

    [self.view addSubview:_playerView];
    playerView.frame = self.playerView.bounds;
    playerView.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
    [self.playerView insertSubview:playerView atIndex:1];
    [self.player setScalingMode:IJKMPMovieScalingModeFill];
 }
-(void)viewWillAppear:(BOOL)animated{
     self.tabBarController.tabBar.hidden = YES;
    if(![self.player isPlaying]){
        [self.player prepareToPlay];
    }
}
-(void)viewWillDisappear:(BOOL)animated{

    [self.player stop];
    self.tabBarController.tabBar.hidden = NO;
    
}
-(void)setString:(NSString *)string{
    

    _string = string;

    
    self.url = [NSURL URLWithString:_string];
    _player =[[IJKFFMoviePlayerController alloc]initWithContentURL:self.url withOptions:nil];
    UIView *playerView = [self.player view];
    UIView *displayView = [[UIView alloc]initWithFrame:self.view.bounds];
    self.playerView = displayView;
//    self.playerView.backgroundColor = [UIColor redColor];
    [self.view addSubview:_playerView];
    playerView.frame = self.playerView.bounds;
    playerView.autoresizingMask = UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;
    [self.playerView insertSubview:playerView atIndex:1];
    [self.player setScalingMode:IJKMPMovieScalingModeFill];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
